<?php
  //This has to be the first line of code a file if sessions are used.
  session_start();
  
  require_once ('check_PDO.php');
  require_once ('appinfo.php');

  if(isset($_SESSION['AppInfo'])) {
    $app = unserialize($_SESSION['AppInfo']);
    if($app->ConnURL == "") {
      header("Location: login.php"); 
      exit; 
    }
  } else {
    header("Location: login.php");
    exit; 
  }

  //Get DB connection info from session data
  include_once ('init_db_connect.php');  

  try {
    $conn_str = "cubrid:dbname=".$dbConfig['DB_DATABASE_NAME'].";host=".$dbConfig['DB_HOST'].";port=30000";
    $conn = new PDO($conn_str, $dbConfig['DB_USERNAME'], $dbConfig['DB_PASSWORD'] );
  } catch(PDOException $e) {
    header("Location: login.php"); 
  }

  require_once ('DBSchema.php');  

  $partitioned = "";
  $reuse_oid = "";
  $owner = "";
  $has_methods = "";
  $columns = "";
  $super_classes = "";
  $sub_classes = "";
  
  if(isset($_GET['object_name'])) {
    $object_name = $_GET['object_name'];

    $sql = "select * from db_class where class_name='".$object_name."'";
    $result = $conn->query($sql);
    if($result != null) {
      foreach ($result as $row) {
        $partitioned = ucfirst(strtolower($row['partitioned']));
        $reuse_oid = ucfirst(strtolower($row['is_reuse_oid_class']));
        $owner = $row['owner_name'];
      }
    }
    
    $sql = "select * from _db_class where class_name='".$object_name."'";
    $result = $conn->query($sql);
    if($result != null) {
      foreach ($result as $row) {
        $has_methods = $row['class_meth_count'];
        $columns = $row['inst_attr_count'];
        $super_classes = ($row['super_classes'] == null ? 'No' : 'Yes');
        $sub_classes = ($row['sub_classes'] == null ? 'No' : 'Yes');
      }
    }
  } else {
    exit; 
  }  
?>

<html>
  <head>
    <title>Table info: <?php echo $object_name; ?></title>
    <link rel="stylesheet" href="css/default.css">
  </head>
  <body bgcolor="#F7F7F7">
    <br />
    <p align="center" class="title2">Table: <font color="red"><?php echo $object_name; ?></font></p>
    <div style="width: 100%; padding: 20px;" align="center">
      <table>
        <tr bgcolor="#FFFFFF">
          <td width="100px;" style="padding-left: 10px; padding-right: 10px;">Is partitioned:</td>
          <td style="padding-left: 10px; padding-right: 10px;"><b style="color: navy"><?php echo $partitioned; ?></b></td>
        </tr>
        <tr>
          <td style="padding-left: 10px; padding-right: 10px;">Reuses OID:</td>
          <td style="padding-left: 10px; padding-right: 10px;"><b style="color: navy"><?php echo $reuse_oid; ?></b></td>
        </tr>
        <tr bgcolor="#FFFFFF">
          <td style="padding-left: 10px; padding-right: 10px;">Owner:</td>
          <td style="padding-left: 10px; padding-right: 10px;"><b style="color: navy"><?php echo $owner; ?></b></td>
        </tr>
        <tr>
          <td style="padding-left: 10px; padding-right: 10px;">Attributes(Columns) count:</td>
          <td style="padding-left: 10px; padding-right: 10px;"><b style="color: navy"><?php echo $columns; ?></b></td>
        </tr>
        <tr bgcolor="#FFFFFF">
          <td style="padding-left: 10px; padding-right: 10px;">Methods count:</td>
          <td style="padding-left: 10px; padding-right: 10px;"><b style="color: navy"><?php echo $has_methods; ?></b></td>
        </tr>
        <tr>
          <td style="padding-left: 10px; padding-right: 10px;">Has Super-classes:</td>
          <td style="padding-left: 10px; padding-right: 10px;"><b style="color: navy"><?php echo $super_classes; ?></b></td>
        </tr>
        <tr bgcolor="#FFFFFF">
          <td style="padding-left: 10px; padding-right: 10px;">Has Sub-classes:</td>
          <td style="padding-left: 10px; padding-right: 10px;"><b style="color: navy"><?php echo $sub_classes; ?></b></td>
        </tr>
      </table>
    </div>
  </body>
</html>